﻿//Letao Function Libery
//Design By Macrox
//Version : Alfa 0
//<Update>
//[2010-11-09]
// - 创建了乐淘基本框架
// - 添加了Letao.Base.Verify的验证函数库
// - 创建了字符串的trim方法
//[2010-11-10]
// - 创建了Letao.Base.CheckType的类型检查函数库
// - 创建了Letao.Business.WebToolkit的浏览器工具库
// - 创建了购物车和弹出窗的初步构想
//[2010-11-11]
// - 利用jQuery来作为类库的基础框架,减少开发时间
//[2010-11-12]
// - 完成Letao.UI.ModeWindow模态窗口组件的alfa 0版本
//[2010-11-17]
// - 为Letao.UI.ModeWindow模态窗口组件增加了拖拽功能
// - 修改了同时存在多个Letao.UI.ModeWindow模态窗口组件时的关闭bug,现在多个窗口可正常并存
//[2010-11-18]
// - 新增Letao.UI.ModeWindow模态窗口组件的弹出位置，分别为左上角、左下角、右上角和右下角
// - 修改了弹出位置为左下角和右下角的窗口在FireFox下的拖拽bug
// - 优化了模态窗口的工作方式,增加了构造函数实现惰性实例化
// - 加入了外围容器锁定功能
// - 修改了遮罩层的工作模式,但是不能完美解决IE6出现的问题
//[2010-12-02]
// - 修改了Letao.UI.ModeWindow模态窗口组件的关闭bug
// - 完成了购物车的三层架构
//[2010-12-03]
// - 完成了Letao.UI.LazyLoad延迟加载组件
//</Update>

(function ()
{
	//针对原型的方法添加应用支持
	String.prototype.trim = function ()
	{
		var str = this;
		str = str.replace(/^\s\s*/, "");
		var ws = /\s/;
		var i = str.length;
		while (ws.test(str.charAt(--i)));
		return str.slice(0, i + 1);
	}

	//设定乐淘基本命名空间
	var Letao = window.Letao || {};

	//设定基本框架
	Letao = {
		_INSTALL: function ()
		{
			window.Letao = Letao;
		},
		Base: {}, 	//基础层,所有的基础函数库,如数据验证、转换等
		DAO: {}, 	//数据访问层,取数据,一般为Ajax的套接口
		Business: {}, //业务逻辑层,处理数据,作为数据层和显示层的接口
		UI: {}, 	//前端显示层,用来重构和回流DOM,前端的特效显示处理
		Page: {}		//用户页面层,用来做一些页面上特有的功能
	};

	//Letao.Base
	//基础应用函数库
	Letao.Base = {
		//验证函数库
		Verify: {
			//检查输入内容是否通过正则校验
			TestRegExp: function (re, text)
			{
				re = new RegExp(re);
				return re.test(text);
			},
			//验证输入内容是否为空(空字符串或只包含空格的字符串)
			IsEmpty: function (x)
			{
				return typeof x != "string" ?
					 false : (x.trim() != "" ? false : true);
			},
			//验证输入内容是否全为数字(0-9)
			IsNumber: function (x)
			{
				return typeof x == "undefined" ?
					false : (isNaN(x.toString()) ? false : true);
			},
			//验证输入内容是否全为字母(a-Z)
			IsLetter: function (x)
			{
				if (typeof x == "undefined")
				{
					return false;
				}
				var re = /^[A-Za-z]+$/;
				return this.TestRegExp(re, x);
			},
			//验证输入内容是否为小写字母(a-z)
			IsLowerCase: function (x)
			{
				if (typeof x == "undefined")
				{
					return false;
				}
				var re = /^[a-z]+$/;
				return this.TestRegExp(re, x);
			},
			//验证输入内容是否为大写字母(A-Z)
			IsUpperCase: function (x)
			{
				if (typeof x == "undefined")
				{
					return false;
				}
				var re = /^[A-Z]+$/;
				return this.TestRegExp(re, x);
			},
			//验证输入内容是否为字符模式(数字、字母或下划线组成)
			IsChar: function (x)
			{
				if (typeof x == "undefined")
				{
					return false;
				}
				var re = /^\w+$/;
				return this.TestRegExp(re, x);
			},
			//验证输入内容是否为至少包含一个下划线的字符模式(数字、字母和下划线组成,必须有下划线)
			IsCharUnderline: function (x)
			{
				if (typeof x == "undefined")
				{
					return false;
				}
				var re = /^(\w*)(\_+)(\w*)$/;
				return this.TestRegExp(re, x);
			},
			//验证输入内容是否为电话号码的格式(<2至5位的数字区号->5至9位的数字号码)
			IsTelephone: function (x)
			{
				if (typeof x == "undefined")
				{
					return false;
				}
				var re = /^(\((\d{2,5})\)|\d{2,5})?(\s*)(-?)(\s*)(\d{5,9})$/;
				return this.TestRegExp(re, x);
			},
			//验证输入内容是否为手机号码的格式(前缀可能有一个“+86”,和以13X/15X/18X为开头的11位中国手机号码)
			IsPhone: function (x)
			{
				if (typeof x == "undefined")
				{
					return false;
				}
				var re = /^(\+86)?1[3,5,8](\d{9})$/;
				return this.TestRegExp(re, x);
			},
			//验证输入内容是否为身份证的格式(目前只支持中国1代或2代身份证)
			IsIdentityCode: function (x)
			{
				if (typeof x == "undefined")
				{
					return false;
				}
				var re = /^[1-9](\d{5})(([1-9]\d)|([1,2](\d{3})))(0[1-9]|1[0,2])(0[1-9]|[1,2]\d|3[0,1])(\d{3})([0-9Xx]+)$/;
				return this.TestRegExp(re, x);
			}
		},
		CheckType: {
			IsArray: function (obj)
			{
				return obj && typeof (obj) == "object" && typeof (obj.length) == "number" && typeof (obj.splice) == "function";
			}
		},
		Event: (function ()
		{
			var _event = {
				pageX: 0,
				pageY: 0,
				Set: function ()
				{
					var arg = arguments;
					if (arg.length == 0)
					{
						arg = null;
						return this;
					}
					if (arg.length == 1 && typeof arg[0] == "object")
					{
						for (var i in arg[0])
						{
							this[i] = arg[0][i];
						}
						arg = null;
						return this;
					}
					if (arg.length == 2)
					{
						opt[arg[0]] = arg[1];
						arg = null;
						return this;
					}
				}
			}
			function setEvent(e)
			{
				_event.pageX = e.clientX + $(window).scrollLeft();
				_event.pageY = e.clientY + $(window).scrollTop();
			}
			return function (e)
			{
				if (typeof e != "undefined")
				{
					e = e || event;
					setEvent(e);
				}
				return _event;
			}
		})()
	};

	//Letao.DAO
	//数据访问函数库
	Letao.DAO = {
		//购物车数据访问
		ShoppingCart: {
			GetProduct: function (callback)
			{
				$.LT_AJAX("get_trolley_product", null, callback, "user_trolley");
			},
			SetProduct: function (pid, size, count, callback)
			{
				$.LT_AJAX("set_trolley_product", [pid, size, count], callback, "user_trolley");
			},
			RemoveProduct: function (pid, size, callback)
			{
				$.LT_AJAX("remove_trolley_product", [pid, size], callback, "user_trolley");
			}
		}
	}

	//Letao.Business
	//业务逻辑函数库
	Letao.Business = {
		ClickStat: function (elem)
		{
			if (!elem)
			{
				return false;
			}
			elem.bind("click", function ()
			{
				_lt_click_stat($(this).attr("lt_stat_id"));
			});
		},
		//浏览器工具
		WebToolkit: {
			//添加收藏夹
			AddFavorite: function (title, url)
			{
				if (typeof title != "string" || typeof url != "string")
				{
					return false;
				}
				try
				{
					if (window.sidebar)
					{
						window.sidebar.addPanel(title, url, "");
					}
					else if (document.all)
					{
						window.external.AddFavorite(url, title);
					}
					else if (window.opera && window.print)
					{
						return true;
					}
				}
				catch (e)
				{
					alert("您的浏览器相关文件已缺失或损坏,请按Ctrl+D将乐淘网址添加到您的收藏夹/书签中");
				}
			}
		},
		//XHR功能
		XHR: {
			CheckResult: function (r)
			{
				var status = "";
				if (!Letao.Base.CheckType.IsArray(r))
				{
					return "ERROR";
				}
				status = r[0].toString();
				return status;
			}
		},
		//购物车功能
		ShoppingCart: (function ()
		{
			var Data = null; //这是一个购物车的全局的数据存储
			var PromotionData = null;
			var alertData = "";
			var isLock = false; //这是购物车的全局锁，保证同一时间只能调用一个Get/Add/Substract/Remove方法
			var callfunc = null; //这是回调函数，用于Get时的特殊情况，自己做DOM处理
			function Lock(unclear)
			{
				//锁定购物车
				isLock = true;
				//如果不作特殊的限定，就清除购物车的数据存储
				if (typeof unclear == "undefined" || !unclear)
				{
					Data = null;
				}
			}
			function Unlock()
			{
				isLock = false;
			}
			function IsValidSerializationProductCode(pid, size)
			{
				pid += "";
				size += "";
				if (pid.length != 9 || size.length != 3)
				{
					return false;
				}
				return true;
			}
			function CallbackShoppingCart(xhrResult)
			{
				Unlock();
				if (Letao.Business.XHR.CheckResult(xhrResult) != "SUCCESS")
				{
					alertData = "";
					if (Letao.Business.XHR.CheckResult(xhrResult) == "ALERT")
					{
						alertData = xhrResult[1];
					}
					return false;
				}
				Letao.Business.ShoppingCart.Set(xhrResult[1]);

				//开始促销的一些判断
				if (xhrResult.length == 5)
				{
					var pname = xhrResult[2], pprice = xhrResult[3], plink = xhrResult[4];
					var pdata = Letao.Business.ShoppingCart.SerializePromotionData(pname, pprice, plink);
					Letao.Business.ShoppingCart.SetPromotionData(pdata);
				}
				else
				{
					PromotionData = null;
				}

				if (callfunc != null)
				{
					callfunc.call(window, xhrResult[1]);
				}
				callfunc = null;
			}
			return {
				Get: function (func)
				{
					if (isLock)
					{
						return false;
					}
					Lock();
					if (typeof func == "function")
					{
						callfunc = null;
						callfunc = func;
					}
					Letao.DAO.ShoppingCart.GetProduct(CallbackShoppingCart);
				},
				Set: function (data)
				{
					if (isLock)
					{
						return false;
					}
					Lock();
					this.SetData(data);
					Unlock();
				},
				Add: function (pid, size, count, func)
				{
					if (isLock)
					{
						return false;
					}
					Lock();
					if (!IsValidSerializationProductCode(pid, size))
					{
						Unlock();
						return false;
					}
					if (typeof func == "function")
					{
						callfunc = null;
						callfunc = func;
					}
					Letao.DAO.ShoppingCart.SetProduct(pid, size, count, CallbackShoppingCart);
				},
				Substract: function (pid, size, count, func)
				{
					return this.Add(pid, size, count, func);
				},
				Remove: function (pid, size, func)
				{
					if (isLock)
					{
						return false;
					}
					Lock();
					if (!IsValidSerializationProductCode(pid, size))
					{
						Unlock();
						return false;
					}
					if (typeof func == "function")
					{
						callfunc = null;
						callfunc = func;
					}
					Letao.DAO.ShoppingCart.RemoveProduct(pid, size, CallbackShoppingCart);
				},
				GetData: function ()
				{
					return Data;
				},
				SetData: function (data)
				{
					Data = data;
				},
				GetAlert: function ()
				{
					return alertData;
				},
				SetPromotionData: function (pdata)
				{
					PromotionData = pdata;
				},
				SerializePromotionData: function (pname, pprice, plink)
				{
					return {
						PromotionName: pname,
						PromotionPrice: pprice,
						PromotionLink: plink
					}
				},
				GetPromotionData: function ()
				{
					return PromotionData;
				}
			}
		})()
	}

	//Letao.UI
	//前端展示函数库
	Letao.UI = {
		//取得鼠标当前位置
		MousePosition: function (e)
		{
			e = e || window.event;
			var X = e.pageX || e.clientX + document.body.scrollLeft, Y = e.pageY || e.clientY + document.body.scrollTop;
			return {
				positionX: X,
				positionY: Y
			}
		},
		GetArea: function (jqelem)
		{
			if (jqelem.selector == "document")
			{
				return {
					height: $(document).height(),
					width: $(document).width()
				}
			}
			if (jqelem.css("overflow") != "hidden")
			{
				return {
					height: jqelem.height(),
					width: jqelem.width()
				}
			}
			var _jqelem = jqelem.clone();
			_jqelem.css({ "display": "block", "position": "absolute", "overflow": "visible" });
			return {
				height: _jqelem.height(),
				width: _jqelem.width()
			}
		},
		//模态窗口组件
		ModeWindow: (function ()
		{
			var ConstructorInitial = null;
			function constructor()
			{
				//默认的参数接口
				var defaultOption = {
					ID: null,
					Title: "ModeWindow - MacroX",
					Content: "Text in content",
					Statusbar: null,
					Parent: null,
					CloseIcon: {
						ImageSrc: "default",
						Width: 12,
						Height: 12
					},
					Backover: true,
					Frameover: false,
					Drag: false,
					ContainOut: false,
					CSS: {
						border: "1px solid #ddd",
						display: "none",
						padding: "1px",
						position: "absolute",
						"background-color": "#fff"
					},
					TitleCSS: {
						"text-indent": "20px",
						"font-size": "14px",
						"color": "#fff",
						"background-color": "#aaa",
						"line-height": "22px",
						"height": "22px",
						"position": "relative"
					},
					ContentCSS: {
						"padding": "16px 20px",
						"line-height": "18px"
					},
					StatusbarCSS: {}
				};
				var defaultShowOption = {
					reshow: false,
					showType: "fade",
					position: "center",
					relativeTop: 0,
					relativeLeft: 0,
					bindObject: null
				};
				var windowAssembly = [];
				//创建并返回一个模态窗口的引用
				function _CreateWindow(opt)
				{
					var windowID = opt.ID;
					if (!windowID)
					{
						return null;
					}
					if ($("#" + windowID).length > 0)
					{
						return $("#" + windowID);
					}
					var parent = (opt.Parent == null || $(opt.Parent).length == 0) ? $("body") : $(opt.Parent);
					parent.append($("<div>").attr("id", opt.ID).css(opt.CSS));
					return $("#" + windowID);
				}
				//创建模态窗口的架构
				function _SetWindowConstruction(w, opt, isreload)
				{
					isreload = typeof isreload == "boolean" ? isreload : false;
					w.isSet = w.obj.html() == "" ? false : true;
					if (w && w.isSet && !isreload)
					{
						return w;
					}
					if (isreload)
					{
						w.obj.html("");
						w.obj.css(opt.CSS);
					}
					//添加标题栏
					w.obj.append($("<div>").attr("id", "w_uuid_" + opt.ID).css(opt.TitleCSS).html(opt.Title));
					//添加主体内容
					w.obj.append($("<div>").attr("id", "content_uuid_" + opt.ID).css(opt.ContentCSS).html(opt.Content));
					//添加状态栏
					w.obj.append($("<div>").css(opt.StatusbarCSS).html(opt.Statusbar));
					//架构创建完毕,重置标志位
					w.isSet = true;
					w.ID = opt.ID;
					w.UUID = "w_uuid_" + opt.ID;
					w.Option = opt;
					w.Backover = _SetBackover(w);
					w.Frameover = _SetFrameover(w);
					w.CloseIcon = _SetCloseIcon(w);
					w.Drag = _MoveWindow(w);
					w.IsShow = false;
					return w;
				}
				//设置模态窗口的关闭按钮
				function _SetCloseIcon(w)
				{
					if (w.Option.CloseIcon == null)
					{
						return;
					}
					var closeIcon = w.Option.CloseIcon;
					var closeIconImage = closeIcon.ImageSrc == "default" ?
						"http://i.ltimg.cn/letaozu/images/letaozuUI/close.gif" : closeIcon.ImageSrc;
					var closeIconPosition = "5px"; //parseInt(($("#" + w.UUID).height() - closeIcon.Height)/2) + "px";
					$("#" + w.UUID).append(
						$("<div>")
						.attr("id", w.UUID + "_closeicon")
						.css({
							width: closeIcon.Width + "px",
							height: closeIcon.Height + "px",
							position: "absolute",
							right: closeIconPosition,
							top: closeIconPosition,
							cursor: "pointer",
							background: "url(" + closeIconImage + ") no-repeat 0 0"
						}).hover(
							function ()
							{
								$(this).css({
									"background-position": "right 0"
								})
							},
							function ()
							{
								$(this).css({
									"background-position": "0 0"
								})
							}
						).bind("click", function ()
						{
							_WindowClose(w);
						})
					);
					return $("#" + w.UUID + "_closeicon");
				}
				//设置遮罩层
				function _SetBackover(w)
				{
					if (w.Option.Backover == false)
					{
						return null;
					}
					if ($("#MW_BACKOVER").length == 0)
					{
						$("body").append(
							$("<div>")
							.attr("id", "MW_BACKOVER")
							.css({
								"background-color": "#ddd",
								"position": "fixed",
								"top": "0",
								"left": "0",
								"width": "100%",
								"height": "100%",
								"display": "none",
								"opacity": 0.3
							})
						);
						//不完美支持IE6,会出现滚动条bug
						var isIE = !!window.ActiveXObject;
						var isIE6 = isIE && !window.XMLHttpRequest;
						if (isIE6)
						{
							$("#MW_BACKOVER").css({
								"position": "absolute"
							});
						}
					}
					return {
						obj: $("#MW_BACKOVER"),
						Show: function ()
						{
							var zIndex = parseInt(new Date().getTime() / 1000);
							var _overwidth = ($(window).width() > $(document).width()) ? $(window).width() : $(document).width();
							var _overheight = ($(window).height() > $(document).height()) ? $(window).height() : $(document).height();

							$("#MW_BACKOVER").css({
								"width": _overwidth + "px",
								"height": _overheight + "px",
								"z-index": zIndex,
								"display": "block"
							});
						},
						Hide: function ()
						{
							$("#MW_BACKOVER").hide();
						}
					}
				}
				//设置iframe
				function _SetFrameover(w)
				{
					if (w.Option.Frameover == false)
					{
						return null;
					}
					if ($("#MW_FRAMEOVER").length == 0)
					{
						$("body").append(
							$("<div>")
							.attr("id", "MW_FRAMEOVER")
							.css({
								"background-color": "#fff",
								"position": "absolute",
								"display": "none",
								"top": "0",
								"left": "0",
								"overflow": "hidden"
							})
							.html("<iframe border=\"0\" style=\"border:0;margin:0;padding:0\"></iframe>")
						);
					}
					return {
						obj: $("#MW_FRAMEOVER"),
						Show: function ()
						{
							var zIndex = 1;
							var _object = w.obj;
							var _overwidth = _object.outerWidth();
							var _overheight = _object.outerHeight();
							var _overtop = _object.offset().top;
							var _overleft = _object.offset().left;
							$("#MW_FRAMEOVER").css({
								"width": _overwidth + "px",
								"height": _overheight + "px",
								"z-index": zIndex,
								"top": _overtop + "px",
								"left": _overleft + "px",
								"display": "block"
							});
						},
						Hide: function ()
						{
							$("#MW_FRAMEOVER").hide();
						}
					}
				}
				//显示窗口
				function _WindowShow(w, showoption, prevoption, func)
				{
					var showopt = $.extend({}, defaultShowOption, showoption);
					//先显示遮罩层
					if (w.Backover != null && w.Backover.obj.css("display") == "none")
					{
						w.Backover.Show();
					}
					var positionTop = "auto", positionLeft = "auto", positionRight = "auto", positionBottom = "auto";
					if (showopt.reshow)
					{
						if (showopt.showType == "fade")
						{
							w.obj.fadeIn("slow");
						}
						else
						{
							w.obj.show();
						}
						return w;
					}
					var modeWindow = w.obj;
					switch (showopt.position)
					{
						case "center":
							positionTop = $(window).height() / 2 - modeWindow.height() / 2 + $(document).scrollTop() + showopt.relativeTop;
							positionLeft = $(document).width() / 2 - modeWindow.width() / 2 + $(document).scrollLeft() + showopt.relativeLeft;
							break;
						case "abscenter":
							positionTop = $(document).height() / 2 - modeWindow.height() / 2 + $(document).scrollTop() + showopt.relativeTop;
							positionLeft = $(document).width() / 2 - modeWindow.width() / 2 + $(document).scrollLeft() + showopt.relativeLeft;
							break;
						case "left-top-corner":
							positionTop = 0;
							positionLeft = 0;
							break;
						case "left-bottom-corner":
							positionLeft = 0;
							positionBottom = 0;
							break;
						case "right-top-corner":
							positionRight = 0;
							positionTop = 0;
							break;
						case "right-bottom-corner":
							positionRight = 0;
							positionBottom = 0;
							break;
						case "bindto":
							if (showopt.bindObject.length != 0)
							{
								positionTop = showopt.bindObject.offset().top + showopt.relativeTop;
								positionLeft = showopt.bindObject.offset().left + showopt.relativeLeft;
							}
							else
							{
								positionTop = $(window).height() / 2 - modeWindow.height() / 2 + $(document).scrollTop() + showopt.relativeTop;
								positionLeft = $(document).width() / 2 - modeWindow.width() / 2 + $(document).scrollLeft() + showopt.relativeLeft;
							}
							break;
						default:
							positionTop = $(window).height() / 2 - modeWindow.height() / 2 + $(document).scrollTop() + showopt.relativeTop;
							positionLeft = $(document).width() / 2 - modeWindow.width() / 2 + $(document).scrollLeft() + showopt.relativeLeft;
					}
					var zIndex = parseInt(new Date().getTime() / 1000 + 1);
					modeWindow.css({
						top: positionTop == "auto" ? positionTop : positionTop + "px",
						left: positionLeft == "auto" ? positionLeft : positionLeft + "px",
						right: positionRight == "auto" ? positionRight : positionRight + "px",
						bottom: positionBottom == "auto" ? positionBottom : positionBottom + "px",
						"z-index": zIndex
					});

					if (showopt.showType == "fade")
					{
						modeWindow.fadeIn("slow", func);
					}
					else
					{
						modeWindow.show(func);
					}
					if (w.Frameover != null && w.Frameover.obj.css("display") == "none")
					{
						w.Frameover.Show();
					}
					w.IsShow = true;
					return w;
				}
				//关闭窗口
				function _WindowClose(w, windowonly)
				{
					w.obj.hide();
					if (w.Frameover != null)
					{
						w.Frameover.Hide();
					}
					w.IsShow = false;
					if (windowAssembly.length > 0)
					{
						for (var i = 0; i < windowAssembly.length; i++)
						{
							//alert("object equal " + (w!=windowAssembly[i] && windowAssembly[i].IsShow && windowAssembly[i].Backover != null));
							if (w != windowAssembly[i] && windowAssembly[i].IsShow && windowAssembly[i].Backover != null)
							{
								return w;
							}
						}
						if ((typeof windowonly == "undefined" || windowonly && typeof windowonly == "boolean" && windowonly == false) && w.Backover != null)
						{
							w.Backover.Hide();
						}
					}
					return w;
				}
				//拖拽窗口
				function _MoveWindow(w)
				{
					if (!w.Option.Drag)
					{
						return false;
					}
					var titleObj = $("#" + w.UUID);
					var windowMove = window._IS_WINDOW_MOVING || false;
					var windowParent = (w.Option.Parent == null || $(w.Option.Parent).length == 0) ? $("body") : $(w.Option.Parent);

					w.obj.bind("mousedown", function ()
					{
						var zIndex = parseInt(new Date().getTime() / 1000) + 1;
						var _left = $(this).position().left + "px", _top = $(this).position().top + "px";
						$(this).css({ "z-index": zIndex, left: _left, top: _top, right: "auto", bottom: "auto" });
					});
					titleObj.bind("mousedown", function (e)
					{
						if (windowMove)
						{
							//有同步进行的窗口移动事件
							return false;
						}
						windowMove = true;
						var mousePosition = Letao.UI.MousePosition(e);
						var xPoint = mousePosition.positionX, yPoint = mousePosition.positionY;
						var windowTop = w.obj.position().top, windowLeft = w.obj.position().left;
						var zIndex = parseInt(new Date().getTime() / 1000);
						w.obj.css({ "opacity": 0.5 })

						$(document).mousemove(function (e)
						{
							if (!windowMove)
							{
								return false;
							}
							window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
							var m = Letao.UI.MousePosition(e);
							var xPointNow = m.positionX, yPointNow = m.positionY;
							var relativeLeft = xPointNow - xPoint, relativeTop = yPointNow - yPoint;
							//alert(windowParent.offset().top + " " + windowParent.offset().left);
							var wt = (windowTop + relativeTop <= windowParent.offset().top && !w.Option.ContainOut) ? windowParent.offset().top : windowTop + relativeTop,
							wl = (windowLeft + relativeLeft <= windowParent.offset().left && !w.Option.ContainOut) ? windowParent.offset().left : windowLeft + relativeLeft;
							//alert("start " + wl);
							if (!w.Option.ContainOut)
							{
								var _overwidth, _overheight;
								if (w.Option.Parent == null || $(w.Option.Parent).length == 0)
								{
									_overwidth = ($(window).width() > $(document).width()) ? $(window).width() : $(document).width();
									_overheight = ($(window).height() > $(document).height()) ? $(window).height() : $(document).height();
								}
								else
								{
									_overwidth = windowParent.outerWidth();
									_overheight = windowParent.outerHeight();
									//alert("overwidth " + _overwidth);
								}
								//alert(windowParent.offset().top);
								wt = (wt >= _overheight - w.obj.outerHeight() + windowParent.offset().top) ? _overheight - w.obj.outerHeight() + windowParent.offset().top : wt;
								wl = (wl >= _overwidth - w.obj.outerWidth() + windowParent.offset().left) ? _overwidth - w.obj.outerWidth() + windowParent.offset().left : wl;
								//alert("end " + wl);
							}
							w.obj.css({
								"left": wl + "px",
								"top": wt + "px"
							});
							return false;
						});

						$(document).mouseup(function (e)
						{
							windowMove = false;
							w.obj.css({ "opacity": 1 });
							$(this).unbind("mousemove").unbind("mouseup");
							return false;
						});
					});
					return w;
				}

				return function (option)
				{
					//先添加三个引用的对象
					var windowObject = null; //本身的模态窗口对象
					//把参数对象整合成可供使用的参数对象
					var opt = $.extend({}, defaultOption, option);
					opt.CSS = $.extend({}, defaultOption.CSS, option.CSS);
					opt.TitleCSS = $.extend({}, defaultOption.TitleCSS, option.TitleCSS);
					opt.ContentCSS = $.extend({}, defaultOption.ContentCSS, option.ContentCSS);
					opt.CloseIcon = $.extend({}, defaultOption.CloseIcon, option.CloseIcon);
					var prevShowOption = null;
					//先建立模态窗口的容器对象
					windowObject = _CreateWindow(opt);
					if (!windowObject)
					{
						throw new Error("Error : [Letao.UI.ModeWindow] Option.ID is undefined");
						return false;
					}
					//模态窗口对象变异,由单一对象变为复合对象,isSet属性标示了这个模态窗口是否已经建立了它自己的构架
					windowObject = { obj: windowObject, isSet: false };
					//构建模态窗口的内部构架
					windowObject = _SetWindowConstruction(windowObject, opt, false);
					if (!windowObject.isSet)
					{
						throw new Error("Error : [Letao.UI.ModeWindow] Window Object is unconstructed");
						return false;
					}
					windowAssembly.push(windowObject);
					return {
						GetObject: function ()
						{
							return windowObject;
						},
						Show: function (showoption, func)
						{
							if (typeof func != "function")
							{
								func = null;
							}
							windowObject = _WindowShow(windowObject, showoption, prevShowOption, func);
							if (prevShowOption == null)
							{
								prevShowOption = showoption;
							}
						},
						Close: function (windowonly)
						{
							windowObject = _WindowClose(windowObject, windowonly);
						},
						Reload: function (windowoption, showoption)
						{
							var opt = $.extend({}, defaultOption, windowoption);
							opt.CSS = $.extend({}, defaultOption.CSS, windowoption.CSS);
							opt.TitleCSS = $.extend({}, defaultOption.TitleCSS, windowoption.TitleCSS);
							opt.ContentCSS = $.extend({}, defaultOption.ContentCSS, windowoption.ContentCSS);
							windowObject = _SetWindowConstruction(windowObject, opt, true);
							windowObject = this.Show(showoption);
						},
						SetContent: function (content)
						{
							if ($("#content_uuid_" + windowObject.ID).length == 1)
							{
								$("#content_uuid_" + windowObject.ID).html(content);
							}
						}
					}
				}
			}
			return function (option)
			{
				if (ConstructorInitial == null)
					ConstructorInitial = constructor();
				return ConstructorInitial(option);
			}
		})(),
		YellowFade: (function ()
		{
			var yfObject = null;
			var loadObject = {
				object: null,
				_createYellowFadeObject: function ()
				{
					var yf = $("<span>")
							.css({
								"border": "1px solid #FFE591",
								"background": "url(http://i.ltimg.cn/letaozu/images/letaozuUI/ajax-loader-smallsnake.gif) no-repeat scroll 8px center #FFFAEA",
								"position": "absolute",
								"padding": "4px 16px 4px 30px",
								"opacity": 0,
								"z-index": 9999
							});
					$("body").append(yf);
					this.object = yf;
					return yf;
				}
			};
			var noloadObject = {
				object: null,
				_createYellowFadeObject: function ()
				{
					var yf = $("<span>")
							.css({
								"border": "1px solid #FFE591",
								"position": "absolute",
								"background-color": "#FFFAEA",
								"padding": "4px 16px",
								"opacity": 0,
								"z-index": 9999
							});
					$("body").append(yf);
					this.object = yf;
					return yf;
				}
			};
			function getShowOption(ev, direction)
			{
				var zIndex = parseInt(new Date().getTime() / 1000) + 10;
				switch (direction)
				{
					case "up":
						return { from: { left: ev().pageX + 16, top: ev().pageY + 30, display: "block", "z-index": zIndex }, to: { top: ev().pageY + 10, opacity: 0.8} };
						break;
					case "left":
						return { from: { left: ev().pageX + 100, top: ev().pageY + 10, display: "block", "z-index": zIndex }, to: { left: ev().pageX + 20, opacity: 0.8} };
						break;
				}
				return null;
			}
			function getHideOption(ev, direction)
			{
				switch (direction)
				{
					case "up":
						return { top: ev.pageY - 50, opacity: 0 };
						break;
					case "right":
						return { left: ev.pageX + 120, opacity: 0 };
						break;
				}
				return { top: ev.pageY - 50, opacity: 0 };
			}
			return {
				Show: function (message, ev, isload, direction)
				{
					ev = ev || Letao.Base.Event;
					var _yfObject = typeof isload == "undefined" || isload ? loadObject : noloadObject;
					var direction = (typeof direction == "undefined" ? "up" : direction);

					if (_yfObject.object == null)
					{
						yfObject = _yfObject._createYellowFadeObject();
					}
					else
					{
						yfObject = _yfObject.object;
					}
					yfObject.stop(true, true);
					var op = getShowOption(ev, direction);
					yfObject.html(message).css(op.from).animate(op.to, 500);
				},
				Hide: function (direction)
				{
					var direction = (typeof direction == "undefined" ? "up" : direction);

					var ev = Letao.Base.Event();
					var opt = getHideOption(ev, direction);
					yfObject.animate(opt, 500, function ()
					{
						$(this).hide();
					});
				}
			}
		})(),
		//购物车前端函数
		ShoppingCart: {
			Data: null,
			SerializationData: function (data, pdata)
			{
				var totalCount = 0, totalPrice = 0;
				var dtNoStock = { Rows: [] }, dr = data.Rows;
				var pid, pname, pimage, psize, pcount, pprice, purl, pvprice;
				var html = "";
				if (dr.Count == 0)
				{
					html += "<div style=\"height:20px; line-height:20px; font-size:14px; color:#ccc; text-align:center; padding:20px 0\">" +
							"<img src=\"http://i.ltimg.cn/letaozu/images/ui/cart.gif\" alt=\"\" />&nbsp;&nbsp;" +
							"您的购物车中还没有任何商品！</div>";
				}
				else
				{
					html += "<table id=\"shopping_trolley_innertable\">" +
							"<thead><tr>" +
							"<td class=\"prod_image\"></td>" +
							"<td class=\"prod_name\"></td>" +
							"<td class=\"prod_count\"></td>" +
							"</tr></thead>";
					for (var i = 0; i < dr.Count; i++)
					{
						pid = dr[i]["ProductID"].toString().substring(0, 9);
						pname = dr[i]["ProductName"].toString();
						pimage = dr[i]["Image"].toString();
						psize = dr[i]["ProductSize"].toString();
						prsize = dr[i]["ProductID"].toString().substring(9, 12);
						pcount = Math.floor(dr[i]["ProductNum"]);
						pprice = parseFloat(dr[i]["letao_price_discount"]);
						purl = dr[i]["StaticURL"].toString();
						pvprice = parseFloat(dr[i]["letao_vprice"]);

						if (dr[i]["HasStock"] == true)
						{
							if (totalCount == 0) html += "<tbody>";
							totalCount += pcount;
							totalPrice += pprice * pcount;
							html += "<tr><td>" +
									"<a href=\"" + purl + "\" target=\"_blank\">" +
									"<img src=\"" + pimage + "\" alt=\"\" />" +
									"</a>" +
									"</td>" +
									"<td class=\"prod_name\">" +
									"<a href=\"" + purl + "\" target=\"_blank\">" + pname + "</a>" +
									"</td>" +
									"<td>" +
									"<span class=\"tly_prodadd\" " +
									"onclick=\"javascript:Letao.UI.ShoppingCart.AddProduct('" + pid + "','" + prsize + "',1).SetCartInner(function(){Letao.UI.ShoppingCart.SetCartCount('fnMyShopcart1','购物车','件','#f00',true);});\" " +
									"onmouseover=\"javascript:$(this).addClass('tly_prodadd_hover');\"" +
									"onmouseout=\"javascript:$(this).removeClass('tly_prodadd_hover');\" " +
									"title=\"商品数量+1\">" +
									"</span>" +
									"<span class=\"tly_prodnum\">" + pcount + "</span>" +
									"<span class=\"tly_prodsubstract\" " +
									"onclick=\"javascript: if($(this).prev('.tly_prodnum').html()=='1'){ if( !confirm('您确定要将该件商品从购物车中删除吗？')) return false;}; Letao.UI.ShoppingCart.SubstractProduct('" + pid + "','" + prsize + "',-1).SetCartInner(function(){Letao.UI.ShoppingCart.SetCartCount('fnMyShopcart1','购物车','件','#f00',true);});\" " +
									"onmouseover=\"javascript:$(this).addClass('tly_prodsubstract_hover');\"" +
									"onmouseout=\"javascript:$(this).removeClass('tly_prodsubstract_hover');\" " +
									"title=\"" + (pcount == 1 ? "删除此商品" : "商品数量-1") + "\">" +
									"</span>" +
									"</td></tr>" +
									"<tr class=\"prod_price\">" +
									"<td></td>" +
									"<td style=\"text-align:left;\">专柜价：" + pvprice + "元&nbsp;&nbsp;&nbsp;&nbsp;乐淘价：<i>" + pprice + "元</i></td>" +
									"<td style=\"text-align:right;\">[<a href=\"javascript:void(0);\" onclick=\"javascript:Letao.UI.ShoppingCart.MoveToCollect($(this),'" + pid + "','" + prsize + "')\">移入收藏夹</a>]</td>" +
									"</tr>";
						}
						else
						{
							dtNoStock.Rows.push(dr[i]);
						}
					}

					if (totalCount > 0)
						html += "</tbody>";
					html += "<tfoot>";
					if (totalCount > 0)
					{
						html += "<tr>" +
							"<td colspan=\"3\" class=\"prodtotal\" style=\"height:18px;line-height:18px;padding-top:18px\">" +
							"<input type=\"hidden\" id=\"hid_prod_count\" value=\"" + totalCount + "\" />" +
							"数量总计：" + totalCount + "件&nbsp;&nbsp;&nbsp;" +
							"金额总计：<strong>" + totalPrice + "元</strong>";
						var realTotalPrice = totalPrice;
						if (pdata != null)
						{
							html += "</td></tr><tr><td class=\"prodtotal\" colspan=\"3\">" +
								"满立减：<strong style=\"color:#008CD6;margin-right:2px\">-" + pdata.PromotionPrice + "元</strong>";

							var _promotion_desc = pdata.PromotionName;
							if (_promotion_desc.length > 25) _promotion_desc = _promotion_desc.slice(0, 25) + "...";
							if (pdata.PromotionLink == "")
							{
								html += "(" + _promotion_desc + ")";
							}
							else
							{
								html += "<a href=\"" + pdata.PromotionLink + "\" target=\"_blank\" style=\"color:#999\" title=\"" + pdata.PromotionName + "\">" +
								"(" + _promotion_desc + ")" +
								"</a>";
							}
							html += "</td></tr>";
							realTotalPrice = realTotalPrice - pdata.PromotionPrice;
						}
						html += "<tr>" +
							"<td colspan=\"3\" style=\"text-align:right;\">" +
							"应支付金额:" +
							"<i class=\"ltbigprice\">" + realTotalPrice + "元</i>" +
							"</td></tr>" +
							"<tr>" +
							"<td colspan=\"3\" class=\"prodtotal\" style=\"padding-bottom:12px\">" +
							"<a href=\"/letaozu/pay/create_order.aspx\" target=\"_blank\"><img src=\"http://i.ltimg.cn/letaozu/images/ui/sc_buy4.gif\" class=\"btn_toorder\" /></a>" +
							"</td></tr>";
					}
					if (dtNoStock.Rows.length != 0)
					{
						var drNS = dtNoStock.Rows;
						html += "<tr>" +
								"<td colspan=\"3\" style=\"text-align:left; color:#999; border-bottom:1px solid #eee; padding:10px 0 5px;\">" +
								"以下商品已售罄，暂无法购买" +
								"</td></tr>";
						for (var i = 0; i < drNS.length; i++)
						{
							pid = drNS[i]["ProductID"].toString().substring(0, 9);
							pname = drNS[i]["ProductName"].toString();
							pimage = drNS[i]["Image"].toString();
							psize = drNS[i]["ProductSize"].toString();
							prsize = drNS[i]["ProductID"].toString().substring(9, 12);
							pcount = Math.floor(drNS[i]["ProductNum"]);
							pprice = parseFloat(drNS[i]["letao_price_discount"]);
							pvprice = parseFloat(drNS[i]["letao_vprice"]);
							html += "<tr>" +
									"<td class=\"prod_image\">" +
									"<a href=\"" + purl + "\" target=\"_blank\">" +
									"<img src=\"" + pimage + "\" alt=\"\" />" +
									"</a>" +
									"</td>" +
									"<td class=\"prod_name nostock\">" +
									"<a href=\"" + purl + "\" target=\"_blank\">" + pname + "</a>" +
									"</td>" +
									"<td style=\"text-align:right; color:#999;\">" +
									"数量：" + pcount + "件" +
									"</td></tr>" +
									"<tr class=\"prod_price\">" +
									"<td></td>" +
									"<td style=\"text-align:left;\">专柜价：" + pvprice + "元&nbsp;&nbsp;&nbsp;&nbsp;乐淘价：<i>" + pprice + "元</i></td>" +
									"<td style=\"text-align:right;\">[<a href=\"javascript:void(0);\" onclick=\"javascript:Letao.UI.ShoppingCart.RemoveProduct('" + pid + "','" + prsize + "').SetCartInner(function(){Letao.UI.ShoppingCart.SetCartCount('fnMyShopcart1','购物车','件','#f00',true);});\">移除</a>]</td>" +
									"</tr>";
						}
					}
					html += "</tfoot></table>";
				}
				var returnObject = { Count: totalCount, Price: totalPrice, HTML: html };
				return returnObject;
			},
			GetCart: function (func)
			{
				this.Data = null;
				Letao.Business.ShoppingCart.Get(func);
				return this;
			},
			AddProduct: function (pid, size, count, func)
			{
				this.Data = null;
				Letao.Business.ShoppingCart.Add(pid, size, count, func);
				return this;
			},
			SubstractProduct: function (pid, size, count, func)
			{
				this.Data = null;
				Letao.Business.ShoppingCart.Substract(pid, size, count, func);
				return this;
			},
			RemoveProduct: function (pid, size, func)
			{
				this.Data = null;
				Letao.Business.ShoppingCart.Remove(pid, size, func);
				return this;
			},
			CartObject: null,
			ShoppingCartModeWindow: function (data)
			{
				var mw = Letao.UI.ModeWindow({
					ID: "letaoShoppingCart",
					Title: "我的购物车",
					Content: data,
					CSS: {
						width: "402px",
						border: "2px solid #ff7a33"
					},
					TitleCSS: {
						"background-color": "#E8F4FD",
						color: "#333",
						"font-weight": "700"
					},
					ContentCSS: {
						width: "380px",
						padding: "5px 10px 15px"
					},
					CloseIcon: {
						ImageSrc: "http://i.ltimg.cn/letaozu/images/shopcart/closebtn.gif",
						Width: 12,
						Height: 12
					},
					Backover: false,
					Drag: true
				});
				if (this.CartObject == null)
				{
					this.CartObject = mw;
				}
				return mw;
			},
			MoveToCollect: function (obj, prodid, size)
			{
				$.LT_AJAX("add_user_collection", prodid, function (al_return)
				{
					if (al_return && al_return[0] == "SUCCESS")
					{
						Letao.Base.Event().Set({ pageX: obj.offset().left - 70, pageY: obj.offset().top - 10 });
						Letao.UI.YellowFade.Show("收藏商品成功！", Letao.Base.Event, true, "left");
						setTimeout(function ()
						{
							Letao.UI.YellowFade.Hide("right");
							//Letao.UI.ShoppingCart.RemoveProduct(prodid, size);
							//Letao.UI.ShoppingCart.SetCartInner(function ()
							//{
							//Letao.UI.ShoppingCart.SetCartCount('fnMyShopcart1', '购物车', '件', '#f00', true);
							//});
						}, 1600);
					}
					else
					{
						if (al_return == "ERROR:用户未登录")
						{
							Letao.Base.Event().Set({ pageX: obj.offset().left - 90, pageY: obj.offset().top - 10 });
							Letao.UI.YellowFade.Show("请您登录后再收藏商品！", Letao.Base.Event, true, "left");
							setTimeout(function ()
							{
								Letao.UI.YellowFade.Hide("right");
								//window.location.href = "/letaozu/login/login.aspx";
							}, 1600);
						}
						else
						{
							alert(al_return);
						}
					}
				}, "user_collect");
			},
			Show: function (showoption, func)
			{
				var cartData = this.Data;
				if (cartData == null)
				{
					cartData = Letao.Business.ShoppingCart.GetData();
					var loadingData = "<div style=\"padding:30px; background:url(http://i.ltimg.cn/letaozu/images/load/ajax-loader.gif) no-repeat center center\"></div>";
					Letao.UI.ShoppingCart.ShoppingCartModeWindow(loadingData).Show(showoption);
					if (cartData == null)
					{
						var _accepttimes = 500;
						var _timer = setInterval(function ()
						{
							if (!_accepttimes--)
							{
								clearInterval(_timer);
								return;
							}
							cartData = Letao.Business.ShoppingCart.GetData();
							if (cartData != null)
							{
								clearInterval(_timer);
								var pData = Letao.Business.ShoppingCart.GetPromotionData();
								cartData = Letao.UI.ShoppingCart.Data = Letao.UI.ShoppingCart.SerializationData(cartData, pData);
								Letao.UI.ShoppingCart.CartObject.SetContent(cartData.HTML);
								if (typeof func == "function")
								{
									func();
								}
								cartData = null;
							}
						}, 13);
					}
				}
				else
				{
					showoption.reshow = true;
					Letao.UI.ShoppingCart.ShoppingCartModeWindow(cartData).Show(showoption);
					if (typeof func == "function")
					{
						func();
					}
					cartData = null;
				}
			},
			SetCartInner: function (func)
			{
				var cartData = this.Data;
				if (cartData == null)
				{
					cartData = Letao.Business.ShoppingCart.GetData();
					if (cartData == null)
					{
						var _accepttimes = 20;
						var _timer = setInterval(function ()
						{
							if (!_accepttimes--)
							{
								clearInterval(_timer);
								var alertData = Letao.Business.ShoppingCart.GetAlert();
								if (alertData != "")
								{
									alert(alertData);
								}
								return;
							}
							cartData = Letao.Business.ShoppingCart.GetData();
							if (cartData != null)
							{
								clearInterval(_timer);
								var pData = Letao.Business.ShoppingCart.GetPromotionData();
								cartData = Letao.UI.ShoppingCart.Data = Letao.UI.ShoppingCart.SerializationData(cartData, pData);
								Letao.UI.ShoppingCart.CartObject.SetContent(cartData.HTML);
								if (typeof func == "function")
								{
									func();
								}
								cartData = null;
							}
						}, 13);
					}
				}
			},
			//购物车的数量
			SetCartCount: function (elemid, prevstring, sufixstring, color, ishaveparentheses)
			{
				if (Letao.UI.ShoppingCart.Data != null && typeof Letao.UI.ShoppingCart.Data.Count != "undefined" && $("#" + elemid).length == 1)
				{
					if (typeof color != "undefined")
					{
						prevstring += "<i>";
						sufixstring = "</i>" + sufixstring;
					}
					if (typeof ishaveparentheses == "boolean" && ishaveparentheses)
					{
						prevstring += "";
						sufixstring = "" + sufixstring;
					}
					$("#" + elemid).html(prevstring + Letao.UI.ShoppingCart.Data.Count + sufixstring);
				}
			},
			GetCartCount: function ()
			{
				if (Letao.UI.ShoppingCart.Data == null)
				{
					return 0;
				}
				var count = Letao.UI.ShoppingCart.Data.Count;
				if (typeof count == "undefined" || count == null)
				{
					return 0;
				}
				return count;
			}
		},
		//延迟加载
		LazyLoad: {
			_initial: null,
			TYPE: {
				"Image": "Image",
				"Function": "Function"
			},
			LOADANIMATION: {
				FADEIN: "fadeIn"
			},
			fnConfig: (function ()
			{
				var funcs = {};
				var _add = function (id, func)
				{
					funcs[id] = func;
					return this;
				};
				var _get = function (id)
				{
					if (typeof funcs[id] == "undefined")
					{
						return null;
					}
					return funcs[id];
				};
				var _remove = function (id)
				{
					if (typeof funcs[id] == "undefined")
					{
						return false;
					}
					delete funcs[id];
					return true;
				};
				return {
					add: _add,
					get: _get,
					remove: _remove
				};
			})(),
			init: function ()
			{
				var lazyObjects = {
					obj: null,
					length: 0
				};

				var getLazyObjects = function ()
				{
					return $("*[lazyload]");
				};

				var getImageLazyObjects = function ()
				{
					return $("img[lazyload]");
				};

				var getConfigFunction = function (id)
				{
					return Letao.UI.LazyLoad.fnConfig.get(id);
				};

				var initLazyObjects = function (jqObjects, isSetObj)
				{
					var ret = {};
					var _this, _lazy;
					jqObjects.each(function (i)
					{
						_this = $(this);
						_lazy = splitLazyLoadStr($(this).attr("lazyload"));
						ret[i] = {
							entity: $(this),
							type: _lazy.type,
							lazyload: _lazy.lazyload
						};
						lazyObjects.length++;
					});
					if (typeof isSetObj == "boolean" && isSetObj)
					{
						setLazyObjects(ret);
					}
					return ret;
				};

				var setLazyObjects = function (objs)
				{
					lazyObjects.obj = objs;
				};

				var addLazyObjects = function (elem, type, lazyload)
				{
					if (lazyObjects.obj == null)
					{
						lazyObjects.obj = {};
					}
					handler = new Date().getTime() / 1000;
					lazyObjects.obj[handler] = {
						entity: elem,
						type: type,
						lazyload: lazyload
					};
					lazyObjects.length++;
					return;
				};

				var getWindow = function ()
				{
					return {
						left: document.documentElement.scrollLeft || document.body.scrollLeft,
						top: document.documentElement.scrollTop || document.body.scrollTop,
						width: document.documentElement.clientWidth,
						height: document.documentElement.clientHeight
					}
				};

				var getObject = function (obj)
				{
					return {
						left: $(obj).offset().left,
						top: $(obj).offset().top,
						width: $(obj).outerWidth(),
						height: $(obj).outerHeight()
					}
				};

				var splitLazyLoadStr = function (lazyloadstr)
				{
					var splitIndex = lazyloadstr.indexOf(":");
					var lazyType = Letao.UI.LazyLoad.TYPE;
					if (splitIndex <= 0)
					{
						return {
							type: lazyType.Image,
							lazyload: lazyloadstr
						};
					}
					var prev = lazyloadstr.slice(0, splitIndex++),
							next = typeof lazyType[prev] != "undefined" ? lazyloadstr.slice(splitIndex) : lazyloadstr;
					prev = next == lazyloadstr ? "Image" : prev;
					return {
						type: prev,
						lazyload: next
					};
				};

				var each = function ()
				{
					var obj = null, entity = null, lazytype = null, lazyload = null;
					var lazyType = Letao.UI.LazyLoad.TYPE;
					var win = getWindow(), dom;
					for (i in lazyObjects.obj)
					{
						obj = lazyObjects.obj[i];
						entity = obj.entity;

						if (entity.length == 0)
						{
							continue;
						}

						dom = getObject(entity);

						if (isIntersect(dom, win) && typeof lazyObjects.obj[i] != "undefined")
						{
							lazytype = obj.type;
							lazyload = obj.lazyload;
							if (lazytype == lazyType.Image)
							{
								loadImage(entity, lazyload);
								delete lazyObjects.obj[i];
								lazyObjects.length--;
								continue;
							}
							if (lazytype == lazyType.Function)
							{
								loadFunction(entity, lazyload);
								delete lazyObjects.obj[i];
								lazyObjects.length--;
								continue;
							}
						}
					}
				};

				var loadImage = function (elem, src)
				{
					if (typeof loadImage.applying == "undefined")
					{
						loadImage.applying = function (elem, imgsrc)
						{
							var tagName = elem.attr("tagName") || elem.prop("tagName");
							if (tagName.toLowerCase() == "img")
							{
								elem
									.css("display", "none")
									.attr("src", imgsrc)
									.show()
									.removeAttr("lazyload");
							}
							else
							{
								elem
									.css("background", "url(" + src + ") no-repeat 0 0")
									.fadeIn(800)
									.removeAttr("lazyload");
							}
							return;
						}
					}

					var img = new Image();
					img.src = src;

					if (img.complete)
					{
						loadImage.applying(elem, img.src);
						img = null;
					}
					else
					{
						img.onload = function ()
						{
							loadImage.applying(elem, img.src);
							img = null;
						}
					}
				};

				var loadFunction = function (elem, func)
				{
					if (typeof func != "function")
					{
						func = getConfigFunction(func);
					}
					if (!func)
					{
						return;
					}
					func.apply(elem);
				};

				var isIntersect = function (rec1, rec2)
				{
					var lp1 = rec1.left + rec1.width / 2,
							lp2 = rec2.left + rec2.width / 2,
							tp1 = rec1.top + rec1.height / 2,
							tp2 = rec2.top + rec2.height / 2,
							w1 = (rec1.width + rec2.width) / 2,
							h1 = (rec1.height + rec2.height) / 2;
					return Math.abs(lp1 - lp2) <= w1 && Math.abs(tp1 - tp2) <= h1;
				};

				return {
					getLazyObj: getLazyObjects,
					addLazyObj: addLazyObjects,
					initLazyObj: initLazyObjects,
					setLazyObj: setLazyObjects,
					isInter: isIntersect,
					each: each,
					loadImage: loadImage
				}
			},
			Run: function (objs, outer)
			{
				if (this._initial == null)
				{
					this._initial = this.init();
				}
				var lz = this._initial;
				if (typeof objs == "undefined" || typeof objs.length != "number" || typeof objs.size != "function" || typeof objs.each != "function")
				{
					lz.initLazyObj(lz.getLazyObj(), true);
				}
				outer = outer || $(window);
				outer.scroll(function ()
				{
					lz.each();
				});
				outer.resize(function ()
				{
					lz.each();
				});
				lz.each();
				return this;
			},
			Add: function (elem, type, lazyload, func)
			{
				if (this._initial == null)
				{
					this._initial = this.init();
				}
				var lz = this._initial;

				lz.addLazyObj(elem, type, lazyload);

				if (type == this.TYPE.Function)
				{
					this.fnConfig.add(lazyload, func);
				}
				lz.each();
				return this;
			}
		},
		SetClipboard: {
			copy: function (maintext)
			{
				if (window.clipboardData)
				{
					alert("复制成功！");
					return (window.clipboardData.setData("Text", maintext));
				}
				else if (window.netscape)
				{
					try
					{
						netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
					}
					catch (e)
					{
						alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
					};
					var clip = Components.classes['@mozilla.org/widget/clipboard;1'].
                    createInstance(Components.interfaces.nsIClipboard);
					if (!clip) return;
					var trans = Components.classes['@mozilla.org/widget/transferable;1'].
                    createInstance(Components.interfaces.nsITransferable);
					if (!trans) return;
					trans.addDataFlavor('text/unicode');
					var str = new Object();
					var len = new Object();
					var str = Components.classes["@mozilla.org/supports-string;1"].
                    createInstance(Components.interfaces.nsISupportsString);
					var copytext = maintext;
					str.data = copytext;
					trans.setTransferData("text/unicode", str, copytext.length * 2);
					var clipid = Components.interfaces.nsIClipboard;
					if (!clip) return false;
					clip.setData(trans, null, clipid.kGlobalClipboard);
				}
				alert("复制成功！");
				return false;
			},
			bindEvent: function (btnobj, iptobj)
			{
				if (btnobj.length == 0 || iptobj.length == 0)
				{
					return false;
				}
				btnobj.bind("click", function ()
				{
					var content = iptobj.val();
					Letao.UI.SetClipboard.copy(content);
				});
			}
		}
	}

	Letao.Page.HeaderFooter = {
		BindShoppingCart: function (id, showoption)
		{
			showoption = showoption || {};
			$("#" + id).bind("click", function ()
			{
				showoption.bindObject = $(this);
				Letao.UI.ShoppingCart.GetCart().Show(showoption);
			});
		},
		BindGoToPay: function (payid, cartid, showoption)
		{
			$("#" + payid).bind("click", function ()
			{
				Letao.UI.ShoppingCart.GetCart(function (ret)
				{
					var count = ret.Rows.length;
					if (count == 0)
					{
						showoption.bindObject = $("#" + cartid);
						Letao.UI.ShoppingCart.GetCart().Show(showoption);
					}
					else
					{
						window.location.href = "/letaozu/pay/create_order.aspx";
					}
				});
			});
		},
		SmallMenu: (function ()
		{
			function _CreateMenu(id, obj, options, css)
			{

				if ($("#" + id).length != 0)
				{
					return $("#" + id);
				}
				else
				{
					$("body").append(
	                    $("<div>")
	                    .attr("id", id)
	                    .css({
	                    	"position": "absolute",
	                    	"background-color": "#fff",
	                    	"padding": "6px",
	                    	"border": "1px solid #ddd",
	                    	"left": (obj.offset().left - 7) + "px",
	                    	"top": (obj.offset().top - 6) + "px",
	                    	"display": "none",
	                    	"z-index": "3"
	                    })
	                );
					if (typeof css.width != "undefined")
					{
						$("#" + id).css("width", css.width);
					}
					else
					{
						$("#" + id).css("width", obj.outerWidth() + "px");
					}
					obj.clone().appendTo("<h6>").appendTo($("#" + id));
					var _obj = null;
					var _innercontent = "";
					var linkarr = [];
					_innercontent = "<div style=\"padding:0\">";
					for (var i = 0; i < options.length; i++)
					{
						_obj = options[i];
						if (typeof _obj == "string")
						{
							//画条线
							_innercontent += "<p style=\"margin:2px 0 0 0; border-top:1px solid #eee; height:2px; overflow:hidden;\"></p>";
						}
						else
						{
							for (var j in _obj)
							{
								linkarr.push(_obj[j]);
							}
							_innercontent += "<p ><a href=\"" + linkarr[0] + "\" title=\"" + linkarr[1] + "\" target=\"" + linkarr[2] + "\" style=\"line-height: 20px; padding: 0; text-decoration: none;\">" + linkarr[3] + "</a></p>";
							linkarr.length = 0;
							//制作一个连接插进去
						}
					}
					_innercontent += "</div>";
					$("#" + id).append(_innercontent);
					return $("#" + id);
				}
			}
			function _ShowMenu(menuobj)
			{
				//menuobj Show出来
				menuobj.css("display", "block");
			}
			function _HideMenu(menuobj)
			{
				//隐藏menuobj
				menuobj.css("display", "none");
			}
			return function (id, obj, options, css)
			{
				obj.hover(function ()
				{
					var menuobj = _CreateMenu(id, obj, options, css);
					_ShowMenu(menuobj);
					menuobj.hover(function ()
					{

					},
	                function ()
	                {
	                	_HideMenu(menuobj);
	                });
				},
	            function ()
	            {
	            });
			}
			//Ex:
			//var myletaoMenuInner = [];
			//myletaoMenuInner.push({href:"www.xxx.com",title:"xxx",target:"_blank",text:"我的乐淘"});
			//myletaoMenuInner.push({href:"www.xxx.com",title:"xxx",target:"_blank",text:"我的乐淘"});
			//myletaoMenuInner.push("line");
			//Letao.Page.HeaderFooter.SmallMenu("menuid",$("#letaomy"),myletaoMenuInner,{width:"700px"});
		})(),
		SearchBar: (function ()
		{
			function _SearchKeyword(keyword)
			{
				Letao.Base.Event().Set({ pageX: $("#ltsearch").offset().left - 14, pageY: $("#ltsearch").offset().top - 8 });
				if (typeof keyword != "string")
				{
					return false;
				}
				keyword = keyword.trim();
				if (keyword == "" || keyword == "请您输入想要搜索的关键词")
				{
					Letao.UI.YellowFade.Show("请您输入想要搜索的关键词", Letao.Base.Event, false, "left");
					setTimeout(function ()
					{
						Letao.UI.YellowFade.Hide("up");
					}, 1200);
					return false;
				}
				keyword = keyword.replace("'", " ");
				keyword = keyword.replace('"', ' ');
				keyword = keyword.replace("script", " ");
				keyword = keyword.replace("?", " ");
				keyword = keyword.replace("\?", " ");
				keyword = keyword.replace("\/", " ");
				keyword = keyword.replace("\\", " ");
				keyword = keyword.replace("<", "&lt;");
				keyword = keyword.replace(">", "&gt;");
				keyword = encodeURIComponent(keyword);
				//window.location.href = "/s~" + keyword + _SetTimeStamp();
			}
			function _SetTimeStamp()
			{
				var t = new Date();
				var year = t.getUTCFullYear() + "";
				var month = t.getUTCMonth() + 1 < 10 ? "0" + (t.getUTCMonth() + 1) : (t.getUTCMonth() + 1) + "";
				var day = t.getUTCDate() < 10 ? "0" + t.getUTCDate() : t.getUTCDate() + "";
				var hour = t.getUTCHours() < 10 ? "0" + t.getUTCHours() : t.getUTCHours() + "";
				var minute = t.getUTCMinutes() < 10 ? "0" + t.getUTCMinutes() : t.getUTCMinutes() + "";
				var ts = "?ts=" + year + month + day + hour + minute;
				return ts;
			}
			return function (inputobject, buttonobject, defaultkeyword, userkeyword)
			{
				defaultkeyword = defaultkeyword || "请您输入想要搜索的关键词";
				if (typeof userkeyword == "string" && userkeyword.trim() != "")
				{
					inputobject.val(userkeyword);
				}
				else
				{
					inputobject.val(defaultkeyword);
				}
				//绑定焦点事件
				inputobject.focus(function ()
				{
					$(this).css({ color: "#000" });
					if ($(this).val() == defaultkeyword)
					{
						$(this).val("");
					}
				});
				//焦点移除事件
				inputobject.blur(function ()
				{
					$(this).css({ color: "#aaa" });
					if ($(this).val() == "")
					{
						$(this).val(defaultkeyword);
					}
				});
				//键盘回车事件
				inputobject.keypress(function (e)
				{
					e = e || event;
					if (e.keyCode == 13)
					{
						_SearchKeyword($(this).val());
						return false;
					}
				});
				//按钮点击事件
				buttonobject.bind("click", function ()
				{
					_SearchKeyword(inputobject.val());
				});
			}
		})(),
		AddFavorite: function (elem)
		{
			elem.bind("click", function ()
			{
				Letao.Business.WebToolkit.AddFavorite("买鞋子，上乐淘", "http://www.letao.com/");
			});
		},
		BindNavLink: function (hoverObject)
		{
			var current = null;
			hoverObject.hover(function ()
			{
				if ($(this).attr("class") != "nc")
				{
					current = {
						mainObj: $(this),
						prevObj: $(this).prev("b"),
						nextObj: $(this).next("b"),
						outerObj: $(this).parent("li").prev("li")
					};
					current.mainObj.addClass("nd");
					current.prevObj.addClass("nl");
					current.nextObj.addClass("nr");
					current.outerObj.addClass("nobg");
				}
			}, function ()
			{
				if (current)
				{
					current.mainObj.removeClass("nd");
					current.prevObj.removeClass("nl");
					current.nextObj.removeClass("nr");
					current.outerObj.removeClass("nobg");
				}
			});
		},
		CoupanAlert: function ()
		{
			if (Letao.UI.ModeWindow)
			{
				var windowContent = "<p style=\"padding:24px 12px 0; line-height:20px; letter-spacing:0.1em; position:relative\">" +
                    "恭喜！您获得<i class=\"red\">1元</i>购买<i class=\"red\">50元</i>乐淘优惠券特权&nbsp;&nbsp;" +
                    "<a href=\"/shoe-letao-999888888\" target=\"_blank\" onclick=\"$('#letaoNewComerCoupanAlert').hide();\">立即去抢！</a>" +
                    "<span onclick=\"$('#letaoNewComerCoupanAlert').hide();$.LT_AJAX('give_up_get_coupan',null,function(){},'user_coupan');\" style=\"display:block; position:absolute; top:12px; right:8px; width:8px; height:7px; background:url(http://i.ltimg.cn/letaozu/images/ui/yellowalert_close.gif) no-repeat 0 0; cursor:pointer\"></span>" +
                    "</p>";
				var mw = Letao.UI.ModeWindow({
					ID: "letaoNewComerCoupanAlert",
					Title: "",
					Content: windowContent,
					CSS: {
						"border": "0",
						"width": "199px",
						"background": "transparent"
					},
					TitleCSS: {
						"display": "none"
					},
					ContentCSS: {
						"background": "url(http://i.ltimg.cn/letaozu/images/ui/yellowalert.gif) no-repeat 0 0",
						"width": "199px",
						"height": "84px",
						"padding": "0"
					},
					CloseIcon: false,
					Backover: false,
					Drag: false
				});
				mw.Show({
					position: "bindto",
					relativeTop: 15,
					relativeLeft: -80,
					bindObject: $("#lnkRegist")
				});
			}
		},
		Share: (function ()
		{
			var _init = function ()
			{
				this.url = "";
				this.image = "http://i.ltimg.cn/letaozu/images/3rd/share_8365.gif";
				this.title = "";
				this.content = "";
				this.source = "";
				this.addon = "?source=";
			};
			_init.prototype.Encode = function ()
			{
				if (this.url.indexOf("?") >= 0)
				{
					this.addon = "&source=";
				}
				var url = encodeURIComponent(this.url),
                    image = encodeURIComponent(this.image),
                    title = encodeURIComponent(this.title),
                    content = encodeURIComponent(this.content),
                    source = encodeURIComponent(this.source),
                    addon = encodeURIComponent(this.addon);
				return {
					url: url,
					image: image,
					title: title,
					content: content,
					source: source,
					addon: addon
				};
			};
			_init.prototype.To = function (id, source)
			{
				source = source || this.source;
				var normal = this,
                    encode = this.Encode(),
                    url = source == "" ? encode.url : encode.url + encode.addon + source;
				if (id == "tsina")
				{
					window.open("http://v.t.sina.com.cn/share/share.php?url=" + url + "&appkey=2674876054&title=" + encode.content + "&pic=" + encode.image, "_blank", "width=615,height=800");
					return;
				}
				if (id == "renren")
				{
					var _content = this.content.replace("@乐淘网上鞋城", "@乐淘");
					_content = encodeURIComponent(_content);
					window.open("http://www.connect.renren.com/share/sharer?url=" + url + "&title=" + _content, "_blank", "_blank", "width=615,height=505");
					return;
				}
				if (id == "kaixin")
				{
					window.open("http://www.kaixin001.com/repaste/share.php?rtitle=" + encode.content + "&rcontent=" + encode.content + "&rurl=" + url);
					return;
				}
				if (id == "tqq")
				{
					window.open("http://v.t.qq.com/share/share.php?source=a207af85abfc489a835c773edc260832&site=http://www.letao.com&title=" + encode.content + "&pic=" + encode.image + "&url=" + url, "_blank", "width=600,height:500");
					return;
				}
				if (id == "tsohu")
				{
					var _content = this.content.replace("@乐淘网上鞋城", "@乐淘鞋城");
					_content = encodeURIComponent(_content);
					window.open("http://t.sohu.com/third/post.jsp?url=" + url + "&title=" + _content + "&content=utf-8&pic=" + encode.image, "_blank", "width=615,height=505");
					return;
				}
				if (id == "qzone")
				{
					window.open("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + url + "&title=" + encode.content + "&desc=" + encode.content + "&pics=" + encode.image, "_blank", "width=615,height=505");
					return;
				}
				if (id == "qpengyou")
				{
					window.open("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + url + "&to=pengyou&title=" + encode.content + "&desc=" + encode.content + "&pics=" + encode.image, "_blank", "width=615,height=505");
					return;
				}
			};
			return function ()
			{
				return new _init();
			};
		})()
	}

	Letao._INSTALL();
})();

$(function ()
{

	//alert("documentReady");
	//var timea = new Date().getTime();

	try
	{
		document.execCommand("BackgroundImageCache", false, true);
	} catch (e) { }

	//绑定导航菜单
	Letao.Page.HeaderFooter.BindNavLink($("#lttopbar li a"));

	//绑定购物车
	Letao.Page.HeaderFooter.BindShoppingCart("fnMyShopcart1", {
		position: "bindto",
		relativeTop: 30,
		relativeLeft: -260,
		bindObject: null
	}
	);
	Letao.Page.HeaderFooter.BindGoToPay("fnMyGotoPay", "fnMyShopcart1", {
		position: "bindto",
		relativeTop: 30,
		relativeLeft: -260,
		bindObject: null
	});

	//绑定搜索框
	var LT_DEFAULT_SEARCH_KEYWORD = typeof _DEFAULT_SEARCH_KEYWORD == "undefined" ? "" : _DEFAULT_SEARCH_KEYWORD;
	var LT_USER_SEARCH_KEYWORD = typeof _USER_SEARCH_KEYWORD == "undefined" ? "" : _USER_SEARCH_KEYWORD;
	Letao.Page.HeaderFooter.SearchBar($("#iptSearch"), $("#btnSearch"), LT_DEFAULT_SEARCH_KEYWORD, LT_USER_SEARCH_KEYWORD);

	//启动延迟加载
	Letao.UI.LazyLoad.Run();

	var myletaoMenuInner = [];
	myletaoMenuInner.push("line");
	myletaoMenuInner.push({ href: "/letaozu/MyLetao/OrderList.aspx", title: "我的订单", target: "_self", text: "我的订单" });
	myletaoMenuInner.push({ href: "/letaozu/MyLetao/CommentList.aspx", title: "我的评价", target: "_self", text: "我的评价" });
	myletaoMenuInner.push({ href: "/letaozu/MyLetao/MyComment.aspx", title: "我的咨询", target: "_self", text: "我的咨询" });
	myletaoMenuInner.push("line");
	myletaoMenuInner.push({ href: "/letaozu/MyLetao/MyCollection.aspx", title: "我的收藏", target: "_self", text: "我的收藏" });
	myletaoMenuInner.push({ href: "/letaozu/MyLetao/MyCoupan.aspx", title: "我的优惠券", target: "_self", text: "我的优惠券" });
	myletaoMenuInner.push("line");
	myletaoMenuInner.push({ href: "/letaozu/MyLetao/MyAddress.aspx", title: "收货地址", target: "_self", text: "收货地址" });
	myletaoMenuInner.push({ href: "/letaozu/MyLetao/ChangePwd.aspx", title: "修改密码", target: "_self", text: "修改密码" });
	//顶部我的订单下拉列表
	Letao.Page.HeaderFooter.SmallMenu("MyLetao_Menu_DDL", $("#fnMyLetao"), myletaoMenuInner, { width: "60px" });

	var helpMenuInner = [];
	helpMenuInner.push("line");
	helpMenuInner.push({ herf: "/letaozu/help/helpindex.aspx", title: "帮助中心", target: "_blank", text: "帮助中心" });
	helpMenuInner.push({ herf: "/letaozu/help/help.aspx?id=1010#3", title: "留言咨询", target: "_blank", text: "留言咨询" });
	helpMenuInner.push("line");
	helpMenuInner.push({ herf: "/letaozu/help/help.aspx?id=1018", title: "售后服务", target: "_blank", text: "售后服务" });
	//顶部帮助中心下拉列表
	Letao.Page.HeaderFooter.SmallMenu("Help_Menu_DDL", $("#fnHelper"), helpMenuInner, { width: "60px" });

	//收藏乐淘
	Letao.Page.HeaderFooter.AddFavorite($("#collectletao"));
});
